<?php
/******************************************************************************
    NuCMS Framework, for the quick deployment of applications developed in
    php.
    Copyright (C) 2009  Matthew General

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
 * 
 * @author mgeneral
 *
 */
abstract class Module extends Debug {
	####################################################################
	#
	#  Protected Instance Variables
	#
	####################################################################
	/**
	 * @var Array
	 */
	protected $_data;
	
	/**
	 * 
	 * @var unknown_type
	 */
	protected $_templateManager;
	
	/**
	 * @var unknown_type
	 */
	protected $_main;
	####################################################################
	#
	#  Public Methods
	#
	####################################################################
	
	/**
	 * 
	 * @return unknown_type
	 */
	public function __construct(&$main,$templateManager) {
		parent::__construct($main->_settings['all']['appPath']."Config/config.ini");
		$this->_templateManager = $templateManager;
		$this->_main = $main;
		$this->debugMessage(self::DEBUG_ALL,"Module initialized");
		$this->_templateManager->setTemplateName(substr(get_class($this),0,strlen(get_class($this))-strlen("module")));
		$this->_data = Array();
	}

	/**
	 * Used to start the processing of a page
	 * should generate the array information later returned by output()
	 * @return Array
	 * 
	 */
	abstract public function run();
	
	/**
	 * Returns the data as an array
	 * @return Array
	 */
	public function output() {
		$this->debugMessage(self::DEBUG_ALL,"Outputting data to template manager");
		
		return $this->_data;
	}
	
	public function config($var,$section="all") {
		if(isset($this->_settings[$section][$var]))
			return $this->_settings[$section][$var];
		else throw new Error("No data for section ".$section." and variable ".$var);
	}
}
?>